﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AppSocketModel;
using AppSocketService.Vehicle;
using BCGPSCommon;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BCGPSRESTful.Controllers.Phone.Vehicle
{
    /// <summary>
    /// 个人用户手机端车辆信息
    /// </summary>
    [ApiExplorerSettings(GroupName = "PersonApp")]
    [Route("api/[controller]")]
    [ApiController]
    public class PhoneVehiclePersonController : PhoneBaseController
    {
        private readonly IVehiclePersonService  vehiclePersonService;
        #region 构造函数
        /// <summary>
        ///  
        /// </summary>
        /// <param name="vehiclePersonService"></param>
        public PhoneVehiclePersonController(IVehiclePersonService vehiclePersonService)
        {
            this.vehiclePersonService = vehiclePersonService;
        }
        #endregion

        #region 给账户添加新车信息
        /// <summary>
        /// 给账户添加新车信息
        /// </summary>
        /// <returns></returns> 
        [HttpPost("[action]")]
        [ProducesResponseType(typeof(VehicleDto), 200)]
        public ActionResult<VehicleDto> AddNew(VehicleRequestDto vehicleDto)
        {
            return vehiclePersonService.AddNew(vehicleDto);
        }
        #endregion


        #region 获取车辆信息 根据 vehicleNo 
        /// <summary>
        /// 获取车辆信息 根据 vehicleNo 
        /// </summary>
        /// <param name="vehicle_no"></param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(List<VehicleDto>), 200)]
        public ActionResult<List<VehicleDto>> GetVehicleListByVehicleNo(string vehicle_no)
        {
            return vehiclePersonService.GetVehicleListByVehicleNo(vehicle_no);
        }
        #endregion

        #region 获取车辆信息 根据 imei 
        /// <summary>
        /// 获取车辆信息 根据 imei 
        /// </summary>
        /// <param name="imei"></param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(VehicleDto), 200)]
        public ActionResult<VehicleDto> GetVehicleByImei(string imei)
        {
            return vehiclePersonService.GetVehicleByImei(imei);
        }
        #endregion

        #region 修改账户车辆信息 根据 vehicleNo 
        /// <summary>
        /// 修改账户车辆信息 根据 vehicleNo 
        /// </summary>
        /// <param name="vehicleDto"></param>
        /// <returns></returns>
        [HttpPut("[action]")]
        [ProducesResponseType(typeof(VehicleDto), 200)]
        public ActionResult<VehicleDto> Update(VehicleDto vehicleDto)
        {
            return vehiclePersonService.Update(vehicleDto);
        }
        #endregion

        #region 删除账户车辆信息
        /// <summary>
        /// 删除账户车辆信息
        /// </summary>
        /// <param name="imei">设备IMEI</param> 
        /// <returns></returns>
        [HttpDelete("[action]")]
        [ProducesResponseType(typeof(void), 200)]
        public ActionResult Delete(string imei)
        {
            vehiclePersonService.Delete(imei);
            return Ok();
        }
        #endregion

        #region 删除账户全部车辆信息
        /// <summary>
        /// 删除账户全部车辆信息
        /// </summary> 
        /// <returns></returns>
        [HttpDelete("[action]")]
        [ProducesResponseType(typeof(void), 200)]
        public ActionResult DeleteAll()
        {
            vehiclePersonService.DeleteAll();
            return Ok();
        }
        #endregion

        #region 获取指定车辆信息和定位信息
        /// <summary>
        /// 获取指定车辆信息和定位信息
        /// </summary>
        /// <param name="imei"></param> 
        /// <param name="gps_map_type">地图种类</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(VehicleLocationDto), 200)]
        public ActionResult<VehicleLocationDto> QueryVehicleLocation(string imei, GpsMapType? gps_map_type = GpsMapType.GDMAP)
        {
            return vehiclePersonService.GetVehicleLocation(imei, gps_map_type.Value);
        }
        #endregion

        #region 获取指定账户下全部车辆和定位信息  不包含子账户
        /// <summary>
        /// 获取指定账户下全部车辆和定位信息  不包含子账户
        /// </summary> 
        /// <param name="gps_map_type">地图种类</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(List<VehicleLocationDto>), 200)]
        public ActionResult<List<VehicleLocationDto>> QueryVehicleLocationList(GpsMapType? gps_map_type = GpsMapType.GDMAP)
        {
            return vehiclePersonService.GetVehicleLocationList(gps_map_type.Value);
        }
        #endregion

        #region 获取指定账号车辆列表
        /// <summary>
        /// 获取指定账号车辆列表
        /// </summary>
        /// <param name="account_code">账号</param>
        /// <param name="desc"></param>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<VehicleDto>), 200)]
        public ActionResult<PageableList<VehicleDto>> QueryPageVehicleList(string account_code,bool? desc = false, int? index = 0, int? size = 20)
        {
            return vehiclePersonService.SysGetVehicleList(account_code, desc.Value, index.Value, size.Value);
        }
        #endregion
    }
}